
import {fromJS} from 'immutable'
import {OrderRouterList} from './order/routes'
// import {ProductRouterList} from './product/routes'
// import {AddressRouterList} from './address/routes'
// import {RefundRouterList}  from './refund/routes'
// import {StatisRouterList} from './statistics/routes'
// import {MarketRouterList}  from './market/routes'
// import {BannerRouterList}  from './banner/routes'
// import {ClassifyRouterList}  from './classify/routes'
// import {SystemRouterList}  from './system/routes'
// import {IntegralSettingRouterList}  from './integralSetting/routes'
// import {UserRouterList}  from './user/routes'
// import {WxaccRouterList}  from './wxacc/routes'


import {getUserInfo,getToken} from '@utils/store'

import utils from '@utils'
let {menuList=[]} = getUserInfo()
let admin_token=getToken();
console.log(`admin_token=${admin_token}`)
if(menuList.length){
	// 解析成一个tree结构
	menuList = utils.getTreeChild(menuList,1)
}
// 管理后台显示的菜单
let menuShowList = [
// 	...StatisRouterList,
//   ...BannerRouterList,
// 	...ProductRouterList,
	...OrderRouterList,
//   ...MarketRouterList,
// 	...RefundRouterList,
// 	...AddressRouterList,
//   ...ClassifyRouterList,
//   ...UserRouterList,
  // ...WxaccRouterList,
  // ...IntegralSettingRouterList,
	// ...SystemRouterList,
].reduce((arr,item,index)=>{
	// 判断一级大类是否，存在就可以在菜单显示
	// let permiss = menuList.find(it=>it.url==item.path)
	if(admin_token){
		// let permissChildren = permiss.children
		item.key=(index+1).toString()
		let children = item.children&&item.children.reduce((subArr,it,j)=>{
			// 判断二级菜单，存在就可以在菜单显示
			// let child = permissChildren.find(child=>child.url==it.path)
			// if(child){
				it.key = item.key
				it.subKey = `${item.key}-${j}`
				it.breadcrumb = [item.name,it.name]
				subArr.push(it)
			// }
			return subArr
		},[])
		item.children = children
		arr.push(item)
	}
	console.log(arr)
	return arr
},[])
console.log(menuShowList)
// 一级父菜单路由
export const FirstRouteList = fromJS(menuShowList).toJS().reduce((arr,item)=>{
  arr.push({
    path:item.path,
    name:item.name,
    // component:item.component
  })
	return arr 
},[])

// 对应一级下的子路由路径
export const RouteList = fromJS(menuShowList).toJS().reduce((arr,item)=>{
  arr.push(...item.children)
	return arr 
},[])
export default menuShowList